knitr::opts_chunk$set(echo = TRUE)
# Load libraries for homework problems
library(tidyverse)
library(gt)
# Read in the data
abpm_wide <- read_csv('data/abpm_wide_synthetic.csv')
Ambulatory blood pressure monitoring (ABPM) is a technique for assessing a person’s blood pressure (BP). ABPM is conducted with a special device that consists of a BP cuff worn on the participant’s arm and attached to a small recording device worn on the belt. The ABPM device is usually worn for 24 hours, and it records BP periodically (usually at 15-minute or 30-minute intervals). One of the benefits of ABPM is measuring BP during routine daily activities and during sleep instead of in clinical settings. A previous study by Hermida et al. (2018) found that, among all BP derive risk factors, asleep Systolic BP is the most associated with cardiovacular disease events.
I have modified the New York times data to include information about state’s population levels. The data are described below:
c("sleep_time" = "Time of falling asleep",
"awake_time" = "Time of waking up",
"age" = "Participant age, years",
"sex" = "Participant sex at birth",
"race" = "Participant race",
"educ" = "Participant education at exam time",
"smoke" = "Participant smoking status at exam time",
"sbp_0 - sbp_23" = "Systolic BP, hours since midnight",
"dbp_0 - dbp_23" = "Diastolic BP, hours since midnight",
"hr_0 - hr_23" = "Heart rate, hours since midnight"
) %>%
enframe() %>%
gt(rowname_col = "name") %>%
tab_stubhead(label = 'Variable name') %>%
cols_label(value = 'Variable description') %>%
cols_align('right') %>%
tab_source_note("BP = blood pressure") %>%
tab_header(title = 'Dictionary for synthetic ABPM data')
| Dictionary for synthetic ABPM data | |
|---|---|
| Variable name | Variable description |
| sleep_time | Time of falling asleep |
| awake_time | Time of waking up |
| age | Participant age, years |
| sex | Participant sex at birth |
| race | Participant race |
| educ | Participant education at exam time |
| smoke | Participant smoking status at exam time |
| sbp_0 - sbp_23 | Systolic BP, hours since midnight |
| dbp_0 - dbp_23 | Diastolic BP, hours since midnight |
| hr_0 - hr_23 | Heart rate, hours since midnight |
| BP = blood pressure | |
The data (abpm_wide) are printed below:
abpm_wide
Convert the smoke variable in abpm_wide into a factor and exclude participants with missing data for sleep_time, awake_time, and smoke.
Notes:
The factor labels should be
read_rds('solutions/01_solution.rds')
Pivot the data into a longer format.
Notes:
Create a column named id that uniquely identifies each row of abpm_wide.
Pivot the data into a longer form such that each id has a column for sbp, dbp, and hr. You may need to use pivot_longer, then separate, then pivot_wider.
Drop all rows with missing data for sbp, dbp, or hr
read_rds('solutions/02_solution.rds')
Create a factor variable called awake that has values of 'Yes' when participants are awake and 'No' when asleep.
Notes:
There are two scenarios that are relevant:
sleep time is less than awake time
sleep time is greater than awake time.
Be sure to think about how the awake indicator should be defined in both of these scenarios.
The if_else() function is helpful here.
read_rds('solutions/03_solution.rds')
Exclude participants with less than 10 ABPM readings while awake or less than 5 ABPM readings while asleep.
Notes:
pivot functions.read_rds('solutions/04_solution.rds')
Using the data from problem 4, compute the mean systolic BP, diastolic BP, and heart rate for each participant during their awake and asleep periods, separately.
Notes:
After summarizing your data, you will want to use pivot_wider.
Before using pivot_wider, I’d recommend recoding the awake indicator variable so that values of 'Yes' are mapped to 'awk' and values of 'No' are mapped to 'slp'.
Remember to ungroup() your data if necessary.
read_rds('solutions/05_solution.rds')
Tabulate and interpret your findings. Show the mean systolic BP, diastolic BP, and heart rate while awake and asleep for males and females, stratified by race and smoking status, jointly. (see my table for an illustration of joint stratification).
Notes:
To get full credit for this exercise, write three observations about your results. Here is an example (you cannot use this as one of your own observations):
unite() is a helpful function for joint stratification.
You can rename your columns and use tab_spanner_delim for convenience.
read_rds('solutions/06_solution.rds')
| Sex | Systolic blood pressure | Diastolic blood pressure | Heart rate | |||
|---|---|---|---|---|---|---|
| Asleep | Awake | Asleep | Awake | Asleep | Awake | |
| Black, Never smoked | ||||||
| Female | 118.0 | 131.3 | 71.2 | 81.2 | 70.7 | 79.3 |
| Male | 120.1 | 133.2 | 72.1 | 81.9 | 71.8 | 80.5 |
| Black, Former smoker | ||||||
| Female | 118.2 | 132.2 | 71.3 | 81.6 | 71.8 | 81.1 |
| Male | 125.4 | 138.4 | 74.7 | 85.3 | 73.7 | 83.1 |
| Black, Current smoker | ||||||
| Female | 119.8 | 133.5 | 71.6 | 81.7 | 73.5 | 81.6 |
| Male | 120.2 | 134.3 | 72.1 | 83.1 | 75.4 | 83.9 |
| White, Never smoked | ||||||
| Female | 105.4 | 123.3 | 64.2 | 77.2 | 67.6 | 77.6 |
| Male | 110.7 | 127.7 | 67.4 | 79.9 | 67.4 | 77.6 |
| White, Former smoker | ||||||
| Female | 106.3 | 123.8 | 65.1 | 77.3 | 67.9 | 77.6 |
| Male | 111.4 | 128.5 | 66.5 | 79.9 | 68.0 | 77.1 |
| White, Current smoker | ||||||
| Female | 107.8 | 124.6 | 65.4 | 77.7 | 65.5 | 75.0 |
| Male | 118.2 | 133.9 | 73.1 | 81.8 | 69.9 | 78.8 |
Hermida, Ramon C, Juan J Crespo, Alfonso Otero, Manuel Dominguez-Sardina, Ana Moya, Maria T Rios, Maria C Castineira, et al. 2018. “Asleep Blood Pressure: Significant Prognostic Marker of Vascular Risk and Therapeutic Target for Prevention.” European Heart Journal 39 (47): 4159–71.